package com.hzjh.base.frame.fragment

import android.content.Context
import android.graphics.Rect
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import com.hzjh.base.frame.R
import com.hzjh.base.frame.IBaseView


/**
 * 普通的Fragment，基类Fragment
 */

abstract class AbsFragment : Fragment(), IBaseView {

    /**
     * 获取Context对象
     */
    protected lateinit var mActivity: FragmentActivity
    protected lateinit var mContext: Context
    protected var pageExposureValue: Int? = null

    abstract fun setContentView(inflater: LayoutInflater, container: ViewGroup?): View

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mActivity = requireActivity()
        mContext = requireActivity().applicationContext
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return transformRootView(setContentView(inflater, container))
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        view.setTag(R.id.fragment_root_tag, this@AbsFragment)
    }

    override fun onDestroyView() {
        view?.setTag(R.id.fragment_root_tag, null)
        super.onDestroyView()
    }

    //用于转换根数图View(可以对其做一些别的操作,例如加入GLoading)
    protected open fun transformRootView(view: View): View {
        return view
    }

    override fun popSelf() {
        parentFragmentManager.popBackStackImmediate()
    }

}
